#include <glib.h>

#define GLIB_BASE64_BLOCK_SIZE 16

gint main(gint argc, gchar **argv)
{
    gchar *base64_en_data = NULL;
    const guchar *ori_data = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

    g_print("ori_data: %s \n", ori_data);
#if 1
    base64_en_data = g_base64_encode(ori_data, strlen(ori_data));
    g_print("base64 encode:%s -> %s \n", ori_data, base64_en_data);
#endif

    /*decode by step*/
    gint output_len = 0;
    gint state = 0;
    gint save = 0;

    gint en_data_len = strlen(base64_en_data);
    gchar *en_data_ptr = base64_en_data;
    gchar *de_data = g_malloc0(strlen(ori_data));

    while (en_data_len > 0)
    {
        gint block_size = MIN (GLIB_BASE64_BLOCK_SIZE, en_data_len);
        output_len += g_base64_decode_step (en_data_ptr, block_size, de_data+output_len, 
            &state, &save);
        en_data_ptr += block_size;
        en_data_len -= block_size;
    }

    g_print("decode de_data: %s\n", de_data);

    g_free(de_data);
    g_free(base64_en_data);

    return 0;
}